package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzbqAgents;
import com.ruoyi.system.service.IDzbqAgentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代理信息Controller
 * 
 * @author tianxingxia
 * @date 2025-02-07
 */
@RestController
@RequestMapping("/system/agents")
public class DzbqAgentsController extends BaseController
{
    @Autowired
    private IDzbqAgentsService dzbqAgentsService;

    /**
     * 查询代理信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:agents:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzbqAgents dzbqAgents)
    {
        startPage();
        List<DzbqAgents> list = dzbqAgentsService.selectDzbqAgentsList(dzbqAgents);
        return getDataTable(list);
    }

    /**
     * 导出代理信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:agents:export')")
    @Log(title = "代理信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzbqAgents dzbqAgents)
    {
        List<DzbqAgents> list = dzbqAgentsService.selectDzbqAgentsList(dzbqAgents);
        ExcelUtil<DzbqAgents> util = new ExcelUtil<DzbqAgents>(DzbqAgents.class);
        util.exportExcel(response, list, "代理信息数据");
    }

    /**
     * 获取代理信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:agents:query')")
    @GetMapping(value = "/{agentId}")
    public AjaxResult getInfo(@PathVariable("agentId") Integer agentId)
    {
        return success(dzbqAgentsService.selectDzbqAgentsByAgentId(agentId));
    }

    /**
     * 新增代理信息
     */
    @PreAuthorize("@ss.hasPermi('system:agents:add')")
    @Log(title = "代理信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzbqAgents dzbqAgents)
    {
        return toAjax(dzbqAgentsService.insertDzbqAgents(dzbqAgents));
    }

    /**
     * 修改代理信息
     */
    @PreAuthorize("@ss.hasPermi('system:agents:edit')")
    @Log(title = "代理信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzbqAgents dzbqAgents)
    {
        return toAjax(dzbqAgentsService.updateDzbqAgents(dzbqAgents));
    }

    /**
     * 删除代理信息
     */
    @PreAuthorize("@ss.hasPermi('system:agents:remove')")
    @Log(title = "代理信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agentIds}")
    public AjaxResult remove(@PathVariable Integer[] agentIds)
    {
        return toAjax(dzbqAgentsService.deleteDzbqAgentsByAgentIds(agentIds));
    }
}
